package com.jtpay.sdk.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.Toast;

import com.jtpay.sdk.R;
import com.jtpay.sdk.util.DbUtils;
import com.jtpay.sdk.util.GlobalUtil;
import com.jtpay.sdk.util.JftLogUtil;
import com.jtpay.sdk.view.RecycleViewFragment;

import java.io.IOException;

/**
 * Add Export Sqlite3 Database founction
 * */
public class JftPlatformsActivity extends FragmentActivity implements ActivityManagerInterface {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jft_platforms);
        Bundle bundle = getIntent().getExtras();
        if (savedInstanceState == bundle) {
            JftLogUtil.log("JftPlatformsActivity bundle equal!");
        } else {
            JftLogUtil.log("JftPlatformsActivity bundle not equal!");
        }
        if (null == savedInstanceState) {
            FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
            RecycleViewFragment fragment = new RecycleViewFragment();
            fragment.setArguments(bundle);
            fragmentTransaction.replace(R.id.layout_fragment, fragment);
            fragmentTransaction.commit();
        }
        addActivity();
    }

    @Override
    public void addActivity() {
        GlobalUtil.getInstance().addActivity(this);
    }

    public void TimerData(View view){
        Intent intent=new Intent(this, TimerListActivity.class);
        startActivity(intent);
    }
    public void ExportDbToSd(View v) {
        try {
            JftLogUtil.log("database export start ");
            DbUtils.copyRawDBToApkDb();
            Toast.makeText(this, "数据库导出成功", Toast.LENGTH_SHORT).show();
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(this, "数据库导出错误,请检查是否打开存储权限", Toast.LENGTH_SHORT).show();
            JftLogUtil.log("database export error");

        }
    }
}
